function XmlObject()
{
	var xmlHttp = null;
	try
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
		}
	}
	if(xmlHttp == null)
	{
		xmlHttp = new XMLHttpRequest();
	}
	
	if(!xmlHttp)
	{
		alert("Trinh Duyet khong ho tro Ajax");
		return;
	}
	return xmlHttp;
}
function getRequest(param, divID)
{
	if(divID)
	{
		var req = XmlObject();
		var idTimer = 0;
		if(req)
		{
			req.open('GET',param, true);
			req.onreadystatechange = function()
			{
				document.getElementById(divID).innerHTML ="<p align=center><img src='bank/wait.gif'>";
				getItem(req, divID);
			}
			req.send(null);
		}
	}
}
function doUpdate(param)
{
		var req = XmlObject();
		var idTimer = 0;
		if(req)
		{
			req.open('GET',param, true);
			req.onreadystatechange = function()
			{
			if(req.readyState == 4)
			{
	   			if (req.status == 200)
		 		   {
					 //  alert("status 200");
						result = req.responseText;
						alert(result);
		  			}
				else
				{
					   alert('Request khong dung');
					   return false;
				}
			}
			}
		req.send(null);
		}
}

function getItem(req, divID)
{
	if(req.readyState == 4)
	{
	   if (req.status == 200)
	   {
			result = req.responseText;
 			// alert(result);
		    document.getElementById(divID).innerHTML = result;
		  
		}
		else
		{
			alert('Request khong dung');
			document.getElementById(divID).innerHTML = 'Bi loi roi';
		   return false;
		}
	}
}

function postRequest(url, para, divID)
{
	var post = XmlObject();
	
	//	para = '';
	/*for(var i = 0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].name != '')
			para += obj.elements[i].name + '=' + encodeURIComponent(obj.elements[i].value) + '&';
	} */
	
	  //para = encodeURIComponent(para.substring(0, para.length - 1) + '&rand=' + Math.random());

	
	post.onreadystatechange = function()
	{
		document.getElementById(divID).innerHTML = "<p align=center><img src='bank/wait.gif'>";
		getItem(post, divID);
	}
	post.open('POST', url, true);
	post.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	post.setRequestHeader("Content-length", para.length);
	post.setRequestHeader("Connection", "close");
	post.send(para);

}
function isNumberKey(evt)
{
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
           return false;

        return true;
}